#ifndef _HELIX_TGA_IMAGE_H_
#define _HELIX_TGA_IMAGE_H_

#include "../../Helix.h"
#include "../../HObject.h"
#include "Image.h"
#include <string>

using namespace std;

namespace helix
{

	//Header structure for the TGA image format
	typedef struct TgaHeader
	{
		unsigned char IDLength;        /* 00h  Size of Image ID field */
		unsigned char ColorMapType;    /* 01h  Color map type */
		unsigned char ImageType;       /* 02h  Image type code */
		unsigned short CMapStart;       /* 03h  Color map origin */
		unsigned short CMapLength;      /* 05h  Color map length */
		unsigned char CMapDepth;       /* 07h  Depth of color map entries */
		unsigned short XOffset;         /* 08h  X origin of image */
		unsigned short YOffset;         /* 0Ah  Y origin of image */
		unsigned short Width;           /* 0Ch  Width of image */
		unsigned short Height;          /* 0Eh  Height of image */
		unsigned char PixelDepth;      /* 10h  Image pixel size */
		unsigned char ImageDescriptor; /* 11h  Image descriptor byte */
	} TGAHeader;

	class MY_CLASS TGAImage : public Image
	{
	private:
		const static unsigned char RLE_PACKET_TYPE_MASK = 0x80;
		const static unsigned char RLE_PACKET_MASK = 0x7F;
		const static unsigned char RLE_PACKET = 0x80;
		const static unsigned char NON_RLE_PACKET = 0x00;

		const static unsigned char TRUE_COLOR_NON_ENCODED = 2;
		const static unsigned char TRUE_COLOR_ENCODED = 10;

		bool loadTGA(string *fileName);
		bool loadTrueColorNonEncoded(TGAHeader tgaH, ifstream *fileIn);
		bool loadTrueColorEncoded(TGAHeader tgaH, ifstream *fileIn);
		void moveFileToImageData(TGAHeader tgaH, ifstream *fileIn);
		void setHeaderFromByteArray(TGAHeader *tgaH, unsigned char *header);
	public:
		TGAImage(const char *fileName);
		virtual ~TGAImage();
	};

}

#endif


